<?php
/*注意需要重新加载一下jquery.easyui.min.js,否则easyui的validatebox验证不起作用。不能重新加载jquery.js，否则会无法关闭当前dialog和重新reload datagrid*/
?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/includes/easyui/themes/default/tabs.css" />

<script type="text/javascript" src="<?php echo base_url(); ?>/includes/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>/includes/js/jquery/tabs.js"></script>
<script type="text/javascript">
			$(document).ready(function() {
				
				$('#add_form').form( {
					url:'<?php echo site_url("catalog/category/add"); ?>',
					onSubmit : function() {
						//alert($(this).form('validate'));
						return $(this).form('validate');	
					},
					success : function(data) {
						if (data == "succ") {
							$.messager.alert('<?php echo $this->lang->line("system_prompt");?>', '<?php echo $this->lang->line("category_modified");?>！', 'info');
							$('#add_record').window("close");
							$('#test').datagrid('reload');
						} else {
							$.messager.alert('<?php echo $this->lang->line("system_prompt");?>', data, 'error');
						}
					}
				});
				
			

				
			});
</script>	

<script type="text/javascript"><!--
$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

});//--></script> 

<div id="content"> 
     <div class="tab_container">
    <form method="post"  id="add_form"  enctype="multipart/form-data" >
	<ul class="tabs"><li><a href="#tab1"><?php echo $this->lang->line("tab_general"); ?></a></li><li><a href="#tab2"><?php echo $this->lang->line("tab_data"); ?></a></li></ul>
    <br />
            <!----starts General partial---->
        <div id="tab1" class="tab_content">
        <div id="languages" class="htabs">
        <ul class="tabs">
			<?php
				$languages = $this->db->get('language');
				foreach ($languages->result() as $language)
				{ ?>          
            
            <li><a href="#language<?php echo $language->language_id; ?>">
                   <img src="<?php echo base_url(); ?>images/flags/<?php echo $language->image; ?>" title="<?php echo $language->name; ?>" /> <?php echo $language->name; ?>
                </a></li>
	      <?php } ?>
       </ul>
        </div>
			<br />            
			<?php  foreach ($languages->result() as $language)	{ ?>   
		  <div id="language<?php echo $language->language_id; ?>">
            <div class="unit">
            	<label class="label"><?php echo $this->lang->line("category_name"); ?>：</label>
                <input type="text" class="easyui-validatebox" required="true" size="30" maxlength="200" name="name[<?php echo $language->language_id; ?>]" id="name" value="" />
            </div>
            	<br />
			<div class="unit">
            	<label class="label"><?php echo $this->lang->line("meta_tag_description"); ?>：</label>
                <textarea name="meta_description[<?php echo $language->language_id; ?>]" rows="3" cols="30"  ></textarea>
            </div>
			<div class="unit">
            	<label class="label"><?php echo $this->lang->line("meta_tag_keywords"); ?>：</label>
                <textarea name="meta_keyword[<?php echo $language->language_id; ?>]" rows="3" cols="30"  ></textarea>
            </div>
            <div class="unit">
				<label class="label"><?php echo $this->lang->line("description");?>:</label>
				<textarea name="description[<?php echo $language->language_id; ?>]" rows="3" cols="57"  ></textarea>
			</div>
          </div>  
             <?php } ?>

		   </div>          
			<!----end  of general partial----> 
            
			<!----starts Data partial---->
       <div id="tab2" class="tab_content">
            <div class="unit">
            	<label class="label"><?php echo $this->lang->line("categories");?>：</label>
                <select name="parent_id">
                	<option value="0"><?php echo $this->lang->line("none");?></option>
                <?php
				foreach($category_list as $category)
				{
				?>
                	<option value="<?php echo $category['category_id']; ?>"><?php echo $category['name']; ?></option>
                <?php
				}
				?>
                </select>                
            </div>            
            <div class="unit">
            	<label class="label"><?php echo $this->lang->line("category_store"); ?></label>
                <input type="checkbox" name="store_id[]" value="0" checked="checked" /><?php echo $this->lang->line("category_default_store"); ?>
                <?php
				
				foreach($store_info->result() as $stores)
				{
				?>
                	<input type="checkbox" name="store_id[]" value="<?php echo $stores->store_id; ?>" /><?php echo $stores->name; ?>
                <?php	
				}
				?>
            </div>
            <div class="unit">
				<label class="label"><?php echo $this->lang->line("entry_keyword");?>:</label>
				<input type="text" class="easyui-validatebox" size="30" maxlength="200" name="keyword"  value="" />
			</div>
            	<br />            
            <div class="unit">
            	<label class="label"><?php echo $this->lang->line("category_image"); ?>:</label>
            	<div>
                <input type="hidden" name="image" id="logo" value="" />
               
                <img src="<?php echo base_url(); ?>images/no_image.jpg" alt="" id="imgDiv" class="image" width="200" height="200" border="0" onclick="image_upload('logo', 'imgDiv');" />  
                </div>
            </div>
            	<br />
            <div class="unit">
				<label class="label"><?php echo $this->lang->line("entry_top");?>:</label>
				<select name="top">
					<option value="0"><?php echo $this->lang->line("no");?></option>
					<option value="1"><?php echo $this->lang->line("yes");?></option>
				</select>
			</div>            
            <div class="unit">
            	<label class="label"><?php echo $this->lang->line("entry_column");?>:</label>
                <input type="text" class="easyui-validatebox" name="column" value="" size="5" />
            </div>
            <div class="unit">
            	<label class="label"><?php echo $this->lang->line("sort_order");?>:</label>
                <input type="text" class="easyui-validatebox"  size="5" maxlength="5" name="sort_order" value="" />
            </div>          
            <div class="unit">
				<label class="label"><?php echo $this->lang->line("status");?>:</label>
				<select name="status">
					<option value="1"><?php echo $this->lang->line("enabled");?></option>
					<option value="0"><?php echo $this->lang->line("disabled");?></option>
				</select>
			</div>
           </div> 
       		<!----end  of Data partial---->
		
		<div>
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit"><?php echo $this->lang->line("submit");?></button></div></div></li>				
			</ul>
		</div>
	</form>
      </div>
</div>
    
<!-- 图片管理插件 -->
<script type="text/javascript" src="<?php echo base_url(); ?>includes/js/jquery/ui/external/bgiframe/jquery.bgiframe.js"></script>

<script type="text/javascript"><!--
function image_upload(field, preview) {
	$('#dialog').remove();
	
	$('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="<?php echo base_url(); ?>index.php/filemanager/init/' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
	
	$('#dialog').dialog({
		title: 'Image Manager',
		onClose: function (event, ui) {
			if ($('#' + field).attr('value')) {
				$.ajax({
					url: '<?php echo base_url(); ?>index.php/filemanager/image',
					type: 'POST',
					data: 'image=' + encodeURIComponent($('#' + field).attr('value')),
					dataType: 'text',
					success: function(data) {
						$('#' + preview).replaceWith('<img src="' + data + '" alt="" id="' + preview + '" class="image" onclick="image_upload(\'' + field + '\', \'' + preview + '\');" />');
					}
				});
			}
		},	
		bgiframe: false,
		width: 700,
		height: 400,
		resizable: false,
		modal: true
	});
};
//--></script>
<!-- 图片管理插件结束 -->
<script type="text/javascript"><!--
$('#tabs a').tabs(); 
$('#languages a').tabs();
//--></script> 
<?php $this->load->view("common/footer"); ?>